package DD12;

import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class MapT {

	public static void main(String[] args) {
		MapT MT = new MapT();
		//MT.test1();
		//MT.test2();
		MT.test3();
	}
	public void test1() {
		Map m = new HashMap<>();
		m = new Hashtable<>();
		m.put("33", "78");
		m.put("11", "67");
		m.put("22", "76");
		m.put("44", "87");
		System.out.println(m.toString());
		m = new LinkedHashMap<>();
		m.put("33", "78");
		m.put("11", "67");
		m.put("22", "76");
		m.put("44", "87");
		System.out.println(m.toString());
	
	}
	public void test2() {
		Map<String, Integer> m1 = new HashMap<>();
		m1.put("Tom", 67);
		m1.put("Jack", 87);
		m1.put("Bill", 67);
		m1.put("Kili", 79);
		System.out.println(m1);
		System.out.println(m1.get("Jack"));
		System.out.println(m1.containsKey("BILL"));
		System.out.println(m1.containsKey("Bill"));
		System.out.println(m1.containsValue(67));
		Map<String, Integer> m2 = new HashMap<>();
		m2.putAll(m1);
		m2.put("Bill", 99);
		System.out.println(m2); //The position and value of Bill is all changed after we put it again
		Object v1 = m2.remove("Tom");
		System.out.println(v1);
		System.out.println(m2);
		m2.clear();
		System.out.println(m2);
		System.out.println(m2.size());
		System.out.println(m2.isEmpty());
	}
	public void test3() {
		Map<String, Integer> m1 = new HashMap<>();
		m1.put("Tom", 67);
		m1.put("Jack", 87);
		m1.put("Bill", 67);
		m1.put("Kili", 79);
		Set<String> KS = m1.keySet();
		Iterator<String> it = KS.iterator();
		while (it.hasNext()) {
			System.out.println(it.next());
		}
		System.out.println();
		Collection<Integer> KV = m1.values();
		Iterator<Integer> It  = KV.iterator();
		while (It.hasNext()) {
			System.out.println(It.next());
		}
		Set SKV = m1.entrySet();
		Iterator IT = SKV.iterator();
		while (IT.hasNext()) {
			Object o = IT.next();
			 Map.Entry en = ( Map.Entry)o;
			 System.out.println(en.getKey()+" :: "+en.getValue());
//			System.out.println(IT.next());
		}
	}
}
